﻿
@{
    ViewBag.Title = "注册";
    Layout = "~/Views/Shared/_LayoutPage.cshtml";
}


<div class="main layui-clear">
    <fieldset class="layui-elem-field layui-field-title">
        <legend>注册</legend>
    </fieldset>
    <div class="layui-form layui-form-pane">
        <form method="post">
            @Html.AntiForgeryToken()
            <div class="layui-form-item">
                <label for="StaffNo" class="layui-form-label">工号</label>
                <div class="layui-input-inline">
                    <input id="Id" name="Id" required lay-verify="required" autocomplete="off" class="layui-input" placeholder="请输入工号">
                </div>
            </div>
            <div class="layui-form-item">
                <label for="L_StaffName" class="layui-form-label">姓名</label>
                <div class="layui-input-inline">
                    <input id="StaffName" name="StaffName" required lay-verify="required" autocomplete="off" class="layui-input" placeholder="请输入姓名" />
                </div>
                <div class="layui-inline">
                    <div class="layui-input-inline">
                        <i class="layui-icon layui-icon-male" style="color:#10B1EF"></i><input type="radio" name="Gender" value="1" checked>
                        <i class="layui-icon layui-icon-female" style="color:#FF0000"></i><input type="radio" name="Gender" value="2">
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <label for="L_pass" class="layui-form-label">密码</label>
                <div class="layui-input-inline">
                    <input type="password" id="L_pass" name="pass" required lay-verify="pass" autocomplete="off" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label for="L_repass" class="layui-form-label">确认密码</label>
                <div class="layui-input-inline">
                    <input type="password" id="L_repass" name="repass" required lay-verify="repass" autocomplete="off" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-inline">
                    <label class="layui-form-label">部门:</label>
                    <div class="layui-input-block" style="width:190px">
                        <select id="Depart" name="Depart">
                            <option value="1">一部</option>
                            <option value="2">二部</option>
                            <option value="3">三部</option>
                            <option value="4">四部</option>
                            <option value="5">五部</option>
                            <option value="6">六部</option>
                        </select>
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <button class="layui-btn layui-btn-normal" lay-filter="reg" lay-submit>立即注册</button>
            </div>
        </form>
    </div>
</div>
@section scripts{
    <script>
        layui.use(['layer', 'form','validator'], function () {
            var layer = layui.layer
                , $ = layui.jquery
                , form = layui.form
                , validator = layui.validator;


            form.verify({
                pass: function (value) {
                    if (value.length == 0) {
                        return '密码不能为空！';
                    }
                    if (!validator.IsStringLength(value, 6, 16)) {
                        return '密码在6到16个字符之间';
                    }
                },
                repass: function (value) {
                    var pass = $('form').find('input[name=pass]').val();
                    if (pass !== value) {
                        return '两次密码输入不一致';
                    }
                }

            });

            form.on('submit(reg)', function (data) {

                $.post('@Url.Action("Register", "Account")', data.field, function (res) {
                    if (!res.success) {
                        layer.msg(res.message, { icon: 2 });
                        $('#valiCode').click();
                    } else {
                        layer.msg(res.message, { icon: 1, time: 1000  }, function (index) {
                            layer.close(index);
                            location.href = '@Url.Action("Login", "Account")';//跳转至登录页
                        });
                    }

                }, 'json');

                return false;
            });

        })
    </script>
}

